package com.cooldatasoft.web.cms.workExpProperty;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.wicket.AttributeModifier;
import org.apache.wicket.MarkupContainer;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.CheckBox;
import org.apache.wicket.markup.html.form.DropDownChoice;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.form.TextField;
import org.apache.wicket.markup.html.link.ExternalLink;
import org.apache.wicket.markup.html.panel.FeedbackPanel;
import org.apache.wicket.model.Model;
import org.apache.wicket.model.PropertyModel;

import com.cooldatasoft.app.WOCApplication;
import com.cooldatasoft.app.WOCSession;
import com.cooldatasoft.base.BaseViewPage;
import com.cooldatasoft.data.WorkExpProperty;

public class WorkExpPropertyViewPage extends BaseViewPage {

	
	private FeedbackPanel feedbackPanel;
	
	public WorkExpPropertyViewPage(Integer entityId) {
		
		
		MarkupContainer container= new WebMarkupContainer("container");		
		MarkupContainer header = new WebMarkupContainer("header");
		ExternalLink companyWebsiteLink = new ExternalLink("companyWebsiteLink","http://www.cooldatasoft.com","Company Name");
		companyWebsiteLink.add(new AttributeModifier("target",true,new Model("_blank")));
		header.add(companyWebsiteLink);
		container.add(header);
		
		
		MarkupContainer wrapper = new WebMarkupContainer("wrapper");
		MarkupContainer personalInfoDiv = new WebMarkupContainer("personalInfoDiv");
		WorkExpPropertyForm personalInfoForm = new WorkExpPropertyForm("personalInfoForm",entityId);
		personalInfoDiv.add(personalInfoForm);
		wrapper.add(personalInfoDiv);
		
		container.add(wrapper);
		
		add(container);
	}

	
	class WorkExpPropertyForm extends Form{

		private WorkExpProperty workExpProperty;
		
		public WorkExpPropertyForm(String id,Integer entityId) {
			super(id);
			if(entityId!=null){
				workExpProperty = WOCApplication.get().getWorkServiceProxy().getWorkExpPropertyById(entityId);
			}
			Label idLabel = new Label("idLabel","Id");
			Label labelLabel = new Label("labelLabel","Label");
			Label publicLabel = new Label("publicLabel","Is Public");
			Label comboLabel = new Label("comboLabel","Is Combo");
			Label dataTypeLabel = new Label("dataTypeLabel"," Data type");
			Label sequenceLabel = new Label("sequenceLabel"," Sequence");
			
			add(idLabel);
			add(labelLabel);
			add(publicLabel);
			add(comboLabel);
			add(dataTypeLabel);
			add(sequenceLabel);
			
			Label idValue = new Label("idValue",new PropertyModel(this,"workExpProperty.id"));
			TextField labelTextField = new TextField("labelTextField",new PropertyModel(this,"workExpProperty.label"));
			CheckBox publicCheckBox = new CheckBox("publicCheckBox",new PropertyModel(this,"workExpProperty.public"));
			CheckBox comboCheckBox = new CheckBox("comboCheckBox",new PropertyModel(this,"workExpProperty.combo"));
			TextField sequenceTextField = new TextField("sequenceTextField",new PropertyModel(this,"workExpProperty.sequence"));
			
			List<String> dataTypeList = new ArrayList<String>();
			dataTypeList.add("STRING");
			DropDownChoice dataTypeDropDownChoice = 
				new DropDownChoice("dataTypeDropDownChoice",new PropertyModel(this,"workExpProperty.dataType"),dataTypeList);
			
			add(idValue);
			add(labelTextField);
			add(publicCheckBox);
			add(comboCheckBox);
			add(dataTypeDropDownChoice);
			add(sequenceTextField);
			
			Button personalInfoSaveButton = new Button("personalInfoSaveButton");
			add(personalInfoSaveButton);			
		}

		@Override
		protected void onSubmit() {
			//FIXME bu set ler service layer a aktarilmali
			workExpProperty.setCreateUserId(WOCSession.get().getUser().getId());
			workExpProperty.setUpdateUserId(WOCSession.get().getUser().getId());
			workExpProperty.setUpdateDate(new Date());
			WOCApplication.get().getWorkServiceProxy().saveOrUpdate(workExpProperty);
			setResponsePage(WorkExpPropertyListPage.class);
		}

		public WorkExpProperty getWorkExpProperty() {
			return workExpProperty;
		}

		public void setWorkExpProperty(WorkExpProperty workExpProperty) {
			this.workExpProperty = workExpProperty;
		}

		
	}
}
